package stringFun;

public class stringDemo4 {
    public static void main(String[] args) {
        String str = "abcde";
        String compareStr = "edcba";
        //boolean res = rotate(str,compareStr);
        boolean res = rotateDemo(str,compareStr);
        boolean res1 = isHuiwen(str,compareStr);
        System.out.println(res);
        System.out.println(res1);
    }

    public static boolean rotate(String str,String compareStr) {
        boolean flag = false;
        for (int i = 0; i < compareStr.length(); i++) {
            String first = str.substring(0,1);
            String after = str.substring(1);
            String result = after+first;
            str = result;
            System.out.println(result);
            if(result.equals(compareStr)){
                System.out.println("旋转成功");
                flag = true;
                break;
            }
        }
        return flag;
    }

    public static boolean rotateDemo(String str,String compareStr) {
        if(str.length()!=compareStr.length()){
            return false;
        }
        StringBuilder sb = new StringBuilder(str);
        int strength = str.length();
        for (int i = 0; i < strength; i++) {
            char firstChar = sb.charAt(0);
            sb.deleteCharAt(0);
            sb.append(firstChar);
            if (sb.toString().equals(compareStr)) {
                return true;
            }
        }
        return false;
    }
    public static boolean isHuiwen(String str,String compareStr) {
        StringBuilder sb = new StringBuilder(str);
        return sb.reverse().toString().equals(compareStr);
    }
}
